<template>
	<view class="page_body grey_bg">
		<view class="nav_box">
			<view class="nav_item s_flex-row">
				<text class="nav_title">ID：{{userInfo.username}}</text>
				<view class="s_flex-row">
					<text class="nav_button" @click="copyCode">复制</text>
				</view>
			</view>
			<view class="nav_item s_flex-row">
				<text class="nav_title">绑定手机</text>
				<view class="s_flex-row">
					<text class="nav_des">{{userInfo.phone}}</text>
					<u-icon name="arrow-right" size="13" style="margin-left: 4px;"></u-icon>
				</view>
			</view>
		</view>
		<view class="nav_box">
			<view class="nav_item s_flex-row">
				<text class="nav_title">消息推送</text>
				<view class="s_flex-row">
					<switch :checked="msgPush" @change="switchPushChange" color="#32DD6F"></switch>
				</view>
			</view>
			<view class="nav_item s_flex-row" @click="checkUpdate">
				<text class="nav_title">检测更新</text>
				<view class="s_flex-row">
					<text class="nav_des">5.5.0</text>
					<u-icon name="arrow-right" size="13" style="margin-left: 4px;"></u-icon>
				</view>
		
			</view>
		</view>
		<view class="nav_box">
			<view class="nav_item s_flex-row" @click="gotoBlackName">
				<text class="nav_title">黑名单</text>
				<view class="s_flex-row">
					<text class="nav_des">0</text>
					<u-icon name="arrow-right" size="13" style="margin-left: 4px;"></u-icon>
				</view>
			</view>
		</view>
		<view class="nav_box">
			<view class="nav_item s_flex-row" @click="clearCache">
				<text class="nav_title">清除缓存</text>
				<view class="s_flex-row">
					<text class="nav_des">{{storageSize}} M</text>
					<u-icon name="arrow-right" size="13" style="margin-left: 4px;"></u-icon>
				</view>
			</view>
			<view class="nav_item s_flex-row" @click="gotoAbout">
				<text class="nav_title">关于我们</text>
				<view class="s_flex-row">
					<text class="nav_des"></text>
					<u-icon name="arrow-right" size="13" style="margin-left: 4px;"></u-icon>
				</view>
			</view>
		</view>
		
		<!-- 退出登录 -->
		<view class="nav_box" >
			<view class="nav_item">
				<view class="btn_logout" v-if="hasLogin" @click="logout">退出登录</view>
			</view>
		</view>
		
		<view class="nav_box">
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 是否已登录
				hasLogin: false,
				msgPush: false,
				storageSize: 50, //缓存大小
				// 用户信息
				userInfo:{
					username: '',
					phone: ''
				}
			}
		},
		onShow() {
			this.hasLogin = this.$authUtil.isLoginedin(false)
			if(this.hasLogin){
				this.userInfo = this.$store.state.user.info
			}
			//计算 本地缓存大小
			let that = this;
			uni.getStorageInfo({
				success(res) {
					that.storageSize = parseInt(res.currentSize / 1024);
				}
			})
		},
		methods: {
			switchPushChange(e) {
				this.msgPush = e.detail.value;
			},
			copyCode() {
				uni.setClipboardData({
					data: '',
					success() {
						uni.showToast({
							title: '江湖ID已复制成功',
							icon: 'none'
						})
					}
				})
			},
			/**
			 * 检查更新
			 */
			checkUpdate() {
				uni.showToast({
					title: '当前版本已是最新版本',
					icon: 'none'
				})
			},
			/**
			 * 关于我们 跳转
			 */
			gotoAbout() {
				uni.showToast({
					title: '关于我们',
					icon: 'none'
				})
			},
			/**
			 * 黑名单
			 */
			gotoBlackName() {
				uni.showToast({
					title: '黑名单',
					icon: 'none'
				})
			},
			clearCache() {
				uni.clearStorage();
				this.storageSize = 0;
				uni.showToast({
					title: '已清除成功',
					icon: 'none'
				})
			},
			logout(){
				let that = this;
				uni.showModal({
					title: '',
					content: '是否退出登录？',
					success: function (res) {
						if (res.confirm) {
							that.doLogout()
						} else if (res.cancel) {
						}
					}
				});
			},
			async doLogout(){
				let result = await this.$store.dispatch('logout')
				if(result){
					uni.switchTab({
						url: '/pages/center/userCenter'
					})
				}
			}
		}
	}
</script>

<style>
	.nav_box {
		margin-top: 5px;
		display: flex;
		flex-direction: column;
	}
	.s_flex-row{
		display: flex;
		flex-direction: row;
		align-items: center;
	}
	.nav_item {
		height: 50px;
		border-bottom-width: 1px;
		border-bottom-color: #F7F7F7;
		padding: 0 15px;
		background-color: #FFFFFF;
	}

	.nav_title {
		flex: 1;
		font-size: 15px;
		color: #333333;
	}

	.nav_des {
		line-height: 13px;
		font-size: 13px;
		color: #C8CBCE;
	}

	.nav_more {
		width: 20px;
		height: 20px;
	}

	.nav_button {
		font-size: 13px;
		color: #bcbcbc;
		padding: 5px 10px;
		border-radius: 20px;
		border-color: #f1f1f1;
		border-width: 1px;
	}

	.btn_logout {
		font-size: 16px;
		color: #FF0000;
		text-align: center;
		line-height: 50px;
	}
</style>
